<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-basics-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">直购电用户：</label>
            <div class="col-sm-8">
                <select class="form-control m-b" id="userId" name="userId">
                    <option th:each="user : ${users}" th:text="${user.name}" th:value="${user.id}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">录入次数：</label>
            <div class="col-sm-8">
                <input id="name" name="name" class="form-control" type="number" value="1">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">电费月份：</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="resultDate" placeholder="电费月份"
                       name="resultDate"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">电压等级：</label>
            <div class="col-sm-8">
                <select id="voltageGrade" class="form-control m-b" name="voltageGrade"
                        th:with="type=${@dict.getType('voltage_grade')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">目录电价明细类别：</label>
            <div class="col-sm-8">
                <select id="priceDetailType" name="priceDetailType" class="form-control m-b"
                        th:with="type=${@dict.getType('price_detail_type')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        laydate.render({
            elem: "#resultDate",
            type: 'month',
            theme: 'molv',
            trigger: 'click',
            done: function(value, date) {}
        });
    });

    var mydateInput = document.getElementById("resultDate");
    var date = new Date();
    var dateString = date.getFullYear() + "-" + (date.getMonth() + 1);
    mydateInput.value = dateString;

    var prefix = ctx + "service/basics"
    $("#form-basics-add").validate({
        rules: {
            name: {
                required: true,
            },
            resultDate: {
                required: true,
            },
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
//            $.operate.save(prefix + "/add", $('#form-basics-add').serialize());
            save(prefix + "/add", $('#form-basics-add').serialize());
        }
    }
    function save(url, data) {
        $.modal.loading("正在处理中，请稍后...");
        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            success: function (result) {
//                console.log(result);
                window.parent.luru();
//                createMenuItem(url, "费用列表");
                if (result.code == web_status.SUCCESS) {
                    if (window.parent.$("#bootstrap-table").length > 0) {
                        $.modal.close();
                        window.parent.$.modal.msgSuccess(result.msg);
                        window.parent.$.table.refresh();
                    } else if (window.parent.$("#bootstrap-tree-table").length > 0) {
                        $.modal.close();
                        window.parent.$.modal.msgSuccess(result.msg);
                        window.parent.$.treeTable.refresh();
                    } else {
                        $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
                    }
                    var url = prefix + '/detail/' + result.msg;

                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            }
        };
        $.ajax(config)
    }
</script>
</body>
</html>
